<?php 
$accountID = 1;

$mysqlConnection = mysql_connect("localhost", "user", 12345678) or die ("Es ist ein Fehler aufgetreten  Fehlercode: 100");
mysql_select_db("ow") or die ("Es ist ein Fehler aufgetreten  Fehlercode: 101");

$receiver = $_POST["receiver"];
$subject = $_POST["subject"];
$message = $_POST["message"];
$reply = $_POST["reply"];

$receiverIDQueryResult = mysql_query("SELECT accountID FROM Account WHERE name = '$receiver'") or die ("User existiert nicht");
$receiverID = mysql_fetch_object($receiverIDQueryResult)->accountID;


echo "$receiver - $subject - $message - $reply - $receiverID";


if(!isset($reply))
	$messageEntry = "INSERT INTO Messages (sender, receiver, subject, message) VALUES ('$accountID', '$receiverID', '$subject', '$message')";
	
else
	$messageEntry = "INSERT INTO Messages (sender, receiver, subject, message, reply) VALUES ('$accountID', '$receiverID', '$subject', '$message', '$reply')";

$success = mysql_query($messageEntry);
?>

<html>
	<head>
	</head>
	<body>
		<?php 
			if($success == true)
				echo "Erfolgreich gesendet!";
			else
				echo "Ein Fehler ist aufgetreten!";
		?>
		<a href="messages.ui.inc.php">zur&uuml;ck</a>
	</body>
</html>